<?php


namespace App\Http\Controllers\CmsApi;


use App\Http\Controllers\BaseController;
use App\Http\Model\Hint;
use App\Http\Model\OutJson;
use App\Http\Model\SmsAll;
use App\Http\Services\AdServices;
use App\Lib\Response;
use App\Lib\SendSms;
use Illuminate\Http\Request;

class ManagerSmsController extends BaseController
{
    protected $service;//服务实例化
    protected $smsService;//服务实例化

    public function __construct()
    {
        $this->service = new SmsAll();
        $this->smsService = new SendSms();
    }

    /**
     * 群发短信创建接口
     */
    public function create(Request $request)
    {
        $request = $request->all(); //参数接收
        $phone = empty($request['phone']) ? '' : $request['phone'];//手机号
        $sendtime = $request['sendtime']; //发送时间
        $content = $request['content']; //发送内容
        $note = $request['note']; //备注
        $finalstr = $request['finalstr']; //发送手机字符串

        //实例化表
        $res = $this->service->adSmsList($phone, $sendtime, $content, $note, $finalstr);
        if ($res) {
            Response::returnResult(Hint::SUCCESS,$res);
        } else {
            Response::returnResult(Hint::ERR_DB_FAIL, $res);
        }
    }

    /**
     * 更改短信群发内容
     */
    public function change(Request $request)
    {
        $request = $request->all(); //参数接收
        $phone = empty($request['phone']) ? '' : $request['phone']; //手机号
        $sendtime = $request['sendtime']; //发送时间
        $content = $request['content']; //发送内容
        $note = $request['note']; //备注
        $chageid = $request['smsid']; //短信id
        $finalstr = $request['finalstr']; //手机号字符串

        //实例化表
        $res = $this->service->changeSmsList($phone, $sendtime, $content, $note, $finalstr, $chageid);
        if ($res) {
            Response::returnResult(Hint::SUCCESS,$res);
        } else {
            Response::returnResult(Hint::ERR_DB_FAIL, $res);
        }
    }

    /**
     * 撤回状态更改
     *
     */
    public function statuschange(Request $request)
    {
        $request = $request->all(); //参数接收
        if (empty($request['smsid'])) {
            Response::returnResult(Hint::ERR_PARAMS_CHECK_FAIL);
        }
        //实例化表
        $res = $this->service->changeSmsStatus($request['smsid']);
        if ($res) {
            Response::returnResult(Hint::SUCCESS,$res);
        } else {
            Response::returnResult(Hint::ERR_DB_FAIL, $res);
        }
    }

    /**
     * 群发短信接口
     */
    public function sendSms(Request $request)
    {
        $request = $request->all();
        if (empty($request['phonelist'])) {
            Response::returnResult(Hint::ERR_PARAMS_CHECK_FAIL);
        }
        //实例化第三方短信服务
        $res = $this->smsService->tengyuSendAllSms($request['phonelist'], $request['content']);
        if ($res) {
            Response::returnResult(Hint::SUCCESS,$res);
        } else {
            Response::returnResult(Hint::ERR_FAIL, $res);
        }

    }

    /**
     * 获取回执状态
     */
    public function sendSmsStatus(Request $request)
    {
        //实例化第三方短信服务
        $res = $this->smsService->tengyuSendAllStatus();
        if ($res) {
            Response::returnResult(Hint::SUCCESS,$res);
        } else {
            Response::returnResult(Hint::ERR_FAIL, $res);
        }
    }


}